/**
 * 
 */
package bible.sunflower.util;

/**
 * @author zhangyp
 *
 */
public class StringUtil {

	/**
	 * 获取字符串的长度
	 * @param value
	 * @return
	 */
	public static int length(String value) {
        int valueLength = 0;
        String chinese = "[\u0391-\uFFE5]";
        /* 获取字段值的长度，如果含中文字符，则每个中文字符长度为2，否则为1 */
        for (int i = 0; i < value.length(); i++) {
            /* 获取一个字符 */
            String temp = value.substring(i, i + 1);
            /* 判断是否为中文字符 */
            if (temp.matches(chinese)) {
                /* 中文字符长度为2 */
                valueLength += 2;
            } else {
                /* 其他字符长度为1 */
                valueLength += 1;
            }
        }
        return valueLength;
    }
	
	public static void main(String[] args) {
		String str = "10M.zip,30M.rar,50M.rar";
		String[] ss = str.split(",");
		for(String s : ss ){
			System.out.println(s);
		}
		
		String txt = "<?xml version=\"1.0\" encoding=\"GBK\"?><CWGL><HEAD><VER>1.0</VER><SRC>025</SRC><DES>025</DES><APP>PROBANK</APP><MsgNo>6601</MsgNo><MsgNoOld></MsgNoOld><MsgID>016562642466769</MsgID><MsgRef>016562642466769</MsgRef><WorkDate>20130521</WorkDate><Reserve></Reserve></HEAD><MSG><Head><PackNo>1</PackNo><PackBeginDate>20130521</PackBeginDate><AllNum>1</AllNum><AllAmt>20000.00</AllAmt><ChildPackNum>1</ChildPackNum><CurPackNo>1</CurPackNo><CurPackNum>1</CurPackNum><CurPackAmt>20000.00</CurPackAmt><EmpNo>0240</EmpNo><IPAdress>32.188.180.140</IPAdress></Head><Body><Info><BussType>1</BussType><PayId>21</PayId><PayAccount>10132098290022419999800004</PayAccount><AccountType></AccountType><BankBranch>银丰农村商业银行股份有限公司</BankBranch><BankName>银丰农村商业银行股份有限公司</BankName><PaypType>0</PaypType><PayeeEmpid>0240</PayeeEmpid><PayeeCustid></PayeeCustid><Paycor>周*燕</Paycor><AccountCode>6224526010003297201</AccountCode><PayAmount>20000.00</PayAmount></Info></Body></MSG></CWGL>";
		System.out.println("length = " + length(txt));
		System.out.println("len = " + txt.length() );
		 for (int i = 0; i < txt.length(); i++) {
			 System.out.println(txt.substring(i, i + 1));
		 }
	}
}
